<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="strutsTags"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
	<head>
		<script type="text/javascript"
			src="resource/js/configuration/attdMachine.js"></script>
		<script type='text/javascript'
			src='dwr/interface/DwrSyncAttdMachine.js'></script>
	</head>
	<body>
		<table id="table_attdMachine" cellpadding="0" cellspacing="1"
			width="85%" class="tablesorter">
			<thead>
				<tr align="center">
					<th nowrap="nowrap">
						考勤机类型
					</th>
					<th nowrap="nowrap">
						考勤机号
					</th>
					<th nowrap="nowrap">
						考勤机IP
					</th>
					<th nowrap="nowrap">
						考勤机接口
					</th>
					<th nowrap="nowrap">
						考勤机连接密码
					</th>
					<th nowrap="nowrap">
						是否包含指纹
					</th>
					<th nowrap="nowrap">
						备注
					</th>
					<th nowrap="nowrap">
						状态
					</th>
				</tr>
			</thead>
			<tbody id="tbody_attdMachine">
				<s:iterator value="allAttdMachine">
					<tr id="<s:property value='macId'/>" align="center"
						macClass="<s:property value="macClass"/>"
						macStatus="<s:property value="macStatus"/>"
						macHasFinger="<s:property value="macHasFinger" />">
						<td align="center" nowrap="nowrap">
							<s:property value="macClassMean" />
						</td>
						<td align="center" nowrap="nowrap">
							<s:property value="macNo" />
						</td>
						<td align="center" nowrap="nowrap">
							<s:property value="macIP" />
						</td>
						<td align="center" nowrap="nowrap">
							<s:property value="macPort" />
						</td>
						<td align="center" nowrap="nowrap">
							<s:property value="macPassword" />
						</td>
						<td align="center" nowrap="nowrap">
							<s:if test="macHasFinger==0">否</s:if>
							<s:else>是</s:else>
						</td>
						<td align="center" nowrap="nowrap">
							<s:property value="macDesc" />
						</td>
						<td align="center" nowrap="nowrap">
							<s:if test="macStatus==1">启用</s:if>
							<s:else>停用</s:else>
						</td>
					</tr>
				</s:iterator>
			</tbody>
		</table>
		<div class="btnlink">
			<a style="cursor: hand;" id="link_add_attdMachine">新增</a>
			<a style="cursor: hand;" id="link_delete_attdMachine">删除</a>
			<a style="cursor: hand;" id="link_update_attdMachine">修改</a>
			<a style="cursor: hand;" id="link_sort_attdMachine">保存排序</a>
		</div>
		<br>
		<div id="dialog_attdMachine" title="考勤机设置" class="prompt_div_inline"
			style="width: 440;">
			<form id="attdMachineForm" method="post">
				<font id="successMsg" color="red"></font>
				<font id="errorMsg" color="green"></font>
				<input type="hidden" id="macId" name="macId" />
				<input type="hidden" id="macSortId" name="macSortId" />
				<table class="prompt_div_body" width="100%">
					<tr>
						<td>
							考勤机号
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<input id="macNo" type="text" size="20" maxlength="32" />
							<label id="label_macNo"></label>
						</td>
					</tr>
					<tr>
						<td>
							考勤机类型
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<s:select id="macClass" name="macClass" list="map"></s:select>
							<label id="label_macClass"></label>
						</td>
					</tr>
					<tr>
						<td>
							考勤机IP
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<input id="macIP" type="text" size="20" maxlength="64" />
							<label id="label_macIP"></label>
						</td>
					</tr>
					<tr>
						<td>
							考勤机端口
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<input id="macPort" type="text" size="20" maxlength="64" />
							<label id="label_macPort"></label>
						</td>
					</tr>
					<tr>
						<td>
							考勤机连接密码
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<input id="macPassword" type="text" size="20" maxlength="64" />
							<label id="label_macPassword"></label>
						</td>
					</tr>
					<tr>
						<td>
							是否包含指纹
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<s:select id="macHasFinger" name="macHasFinger" required="true"
								list="#{0:'否', 1:'是'}" />
							<label id="label_macHasFinger"></label>
						</td>
					</tr>
					<tr>
						<td>
							状态
							<font color="red">*</font>:
						</td>
						<td class="errorMessage">
							<s:select id="macStatus" name="macStatus" required="true"
								list="#{1:'启用',0:'停用'}" />
							<label id="label_macStatus"></label>
						</td>
					</tr>
					<tr>
						<td>
							备注:
						</td>
						<td class="errorMessage">
							<textarea id="macDesc" cols="30" rows="6"
								onkeyup="if(this.value.length>255){this.value=this.value.substring(0, 255);}"></textarea>
							<label id="label_macDesc"></label>
						</td>
					</tr>
					<tr>
						<td class="prompt_div_bottom" colspan="2">
							<input id="btn_add_attdMachine" class="button" type="button"
								value="新增" />
							<input id="btn_update_attdMachine" class="button" type="button"
								value="修改" />
							<input id="btn_link_machine" class="button" type="button"
								value="连接测试" onclick="linkMachine();" />
							<input id="btn_sync_time" class="button" type="button"
								value="同步时间" onclick="syncTime();" />
							<input id="btn_attdMachine_close" class="button" type="button"
								value="取消" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<script type="text/javascript">
	var config = {
		tableId :"table_attdMachine",
		tbodyId :"tbody_attdMachine",
		dialogId :"dialog_attdMachine",
		updateButton :"btn_update_attdMachine",
		addButton :"btn_add_attdMachine",
		addLink :"link_add_attdMachine",
		deleteLink :"link_delete_attdMachine",
		updateLink :"link_update_attdMachine",
		sortLink :"link_sort_attdMachine",
		closeButton :"btn_attdMachine_close"
	};
	attdMachineManager = new AttdMachineManager(config);

	// 测试考勤机连接；
	function linkMachine() {
		var machineClass = document.getElementById("macClass").value;
		if (machineClass == null || machineClass.trim() == "") {
			alert("考勤机类型不能为空！");
			return;
		}
		var macIP = DWRUtil.getValue("macIP");
		if (macIP == null || macIP.trim() == "") {
			alert("考勤机IP不能为空！");
			return;
		}
		var macPort = DWRUtil.getValue("macPort");
		if (macPort == null || macPort.trim() == "") {
			alert("考勤机接口不能为空！");
			return;
		}
		var macPassword = DWRUtil.getValue("macPassword");
		var macHasFinger = DWRUtil.getValue("macHasFinger");

		document.getElementById('btn_link_machine').disabled = "disabled";
		DwrSyncAttdMachine.linkMachine(macIP, macPort, macPassword,
				macHasFinger, machineClass, callback);
	}
	function callback(result) {
		document.getElementById('btn_link_machine').disabled = "";
		if (result == "success")
			document.getElementById('successMsg').innerHTML = '考勤机连接成功！';
		else
			document.getElementById('errorMsg').innerHTML = errorMsg;
	}

	// 同步考勤机时间；
	function syncTime() {
		var machineClass = document.getElementById("macClass").value;
		if (machineClass == null || machineClass.trim() == "") {
			alert("考勤机类型不能为空！");
			return;
		}
		var macIP = DWRUtil.getValue("macIP");
		if (macIP == null || macIP.trim() == "") {
			alert("考勤机IP不能为空！");
			return;
		}
		var macPort = DWRUtil.getValue("macPort");
		if (macPort == null || macPort.trim() == "") {
			alert("考勤机接口不能为空！");
			return;
		}
		var macPassword = DWRUtil.getValue("macPassword");
		var macHasFinger = DWRUtil.getValue("macHasFinger");
		document.getElementById('btn_sync_time').disabled = "disabled";
		DwrSyncAttdMachine.syncMachineTime(macIP, macPort, macPassword,
				macHasFinger, machineClass, syncTimeCallback);
		function syncTimeCallback(result) {
			document.getElementById('btn_sync_time').disabled = "";
			document.getElementById('successMsg').innerHTML = result;
		}
	}
</script>
	</body>
</html>